// SPDX-License-Identifier: MIT
// Copyright (C) 2018-present iced project and contributors

package com.github.icedland.iced.x86.fmt.masm;

import com.github.icedland.iced.x86.internal.IcedConstants;
import com.github.icedland.iced.x86.internal.fmt.FormatterString;

final class MemorySizes {
	static final FormatterString[] dword_ptr;
	static final FormatterString[] qword_ptr;
	static final FormatterString[] mmword_ptr;
	static final FormatterString[] xmmword_ptr;
	static final FormatterString[] oword_ptr;

	public static final class Info {
		public final boolean isBroadcast;
		public final int size;
		public final FormatterString[] keywords;

		Info(boolean isBroadcast, int size, FormatterString[] keywords) {
			this.isBroadcast = isBroadcast;
			this.size = size;
			this.keywords = keywords;
		}
	}

	static final Info[] allMemorySizes;

	static {
		// GENERATOR-BEGIN: ConstData
		// ⚠️This was generated by GENERATOR!🦹‍♂️
		final int SIZE_KIND_SHIFT = 5;
		final int MEMORY_KEYWORDS_MASK = 31;
		FormatterString byte_ = new FormatterString("byte");
		FormatterString ptr = new FormatterString("ptr");
		FormatterString[] byte_ptr_ = new FormatterString[] { byte_, ptr };
		FormatterString dword = new FormatterString("dword");
		FormatterString bcst = new FormatterString("bcst");
		FormatterString[] dword_bcst_ = new FormatterString[] { dword, bcst };
		FormatterString[] dword_ptr_ = new FormatterString[] { dword, ptr };
		FormatterString fpuenv14 = new FormatterString("fpuenv14");
		FormatterString[] fpuenv14_ptr_ = new FormatterString[] { fpuenv14, ptr };
		FormatterString fpuenv28 = new FormatterString("fpuenv28");
		FormatterString[] fpuenv28_ptr_ = new FormatterString[] { fpuenv28, ptr };
		FormatterString fpustate108 = new FormatterString("fpustate108");
		FormatterString[] fpustate108_ptr_ = new FormatterString[] { fpustate108, ptr };
		FormatterString fpustate94 = new FormatterString("fpustate94");
		FormatterString[] fpustate94_ptr_ = new FormatterString[] { fpustate94, ptr };
		FormatterString fword = new FormatterString("fword");
		FormatterString[] fword_ptr_ = new FormatterString[] { fword, ptr };
		FormatterString oword = new FormatterString("oword");
		FormatterString[] oword_ptr_ = new FormatterString[] { oword, ptr };
		FormatterString qword = new FormatterString("qword");
		FormatterString[] qword_bcst_ = new FormatterString[] { qword, bcst };
		FormatterString[] qword_ptr_ = new FormatterString[] { qword, ptr };
		FormatterString tbyte = new FormatterString("tbyte");
		FormatterString[] tbyte_ptr_ = new FormatterString[] { tbyte, ptr };
		FormatterString word = new FormatterString("word");
		FormatterString[] word_ptr_ = new FormatterString[] { word, ptr };
		FormatterString xmmword = new FormatterString("xmmword");
		FormatterString[] xmmword_ptr_ = new FormatterString[] { xmmword, ptr };
		FormatterString ymmword = new FormatterString("ymmword");
		FormatterString[] ymmword_ptr_ = new FormatterString[] { ymmword, ptr };
		FormatterString zmmword = new FormatterString("zmmword");
		FormatterString[] zmmword_ptr_ = new FormatterString[] { zmmword, ptr };
		FormatterString mem384 = new FormatterString("mem384");
		FormatterString[] mem384_ptr_ = new FormatterString[] { mem384, ptr };
		FormatterString[] word_bcst_ = new FormatterString[] { word, bcst };
		FormatterString mmword = new FormatterString("mmword");
		FormatterString[] mmword_ptr_ = new FormatterString[] { mmword, ptr };
		short[] sizes = new short[] {
			(short)0,
			(short)1,
			(short)2,
			(short)4,
			(short)6,
			(short)8,
			(short)10,
			(short)14,
			(short)16,
			(short)28,
			(short)32,
			(short)48,
			(short)64,
			(short)94,
			(short)108,
			(short)512,
		};
		// GENERATOR-END: ConstData
		mmword_ptr = mmword_ptr_;
		dword_ptr = dword_ptr_;
		oword_ptr = oword_ptr_;
		qword_ptr = qword_ptr_;
		xmmword_ptr = xmmword_ptr_;

		Info[] infos = new Info[IcedConstants.MEMORY_SIZE_ENUM_COUNT];
		short[] data = new short[] {
			// GENERATOR-BEGIN: MemorySizes
			// ⚠️This was generated by GENERATOR!🦹‍♂️
			(short)0x0000,
			(short)0x0021,
			(short)0x004D,
			(short)0x0063,
			(short)0x00AB,
			(short)0x00AB,
			(short)0x010E,
			(short)0x014F,
			(short)0x0190,
			(short)0x0021,
			(short)0x004D,
			(short)0x0063,
			(short)0x00AB,
			(short)0x010E,
			(short)0x014F,
			(short)0x0190,
			(short)0x0063,
			(short)0x0088,
			(short)0x00CC,
			(short)0x004D,
			(short)0x0063,
			(short)0x00AB,
			(short)0x0063,
			(short)0x00AB,
			(short)0x00AB,
			(short)0x0109,
			(short)0x0088,
			(short)0x00C8,
			(short)0x004D,
			(short)0x0063,
			(short)0x00AB,
			(short)0x00CC,
			(short)0x010E,
			(short)0x004D,
			(short)0x00E4,
			(short)0x0125,
			(short)0x01A7,
			(short)0x01C6,
			(short)0x01E0,
			(short)0x01E0,
			(short)0x0000,
			(short)0x0000,
			(short)0x00CC,
			(short)0x0190,
			(short)0x0000,
			(short)0x00CC,
			(short)0x0171,
			(short)0x0190,
			(short)0x004D,
			(short)0x004D,
			(short)0x0063,
			(short)0x0063,
			(short)0x0063,
			(short)0x0063,
			(short)0x0063,
			(short)0x0063,
			(short)0x00AB,
			(short)0x00AB,
			(short)0x00AB,
			(short)0x00AB,
			(short)0x00AB,
			(short)0x00AB,
			(short)0x00AB,
			(short)0x00AB,
			(short)0x010E,
			(short)0x010E,
			(short)0x010E,
			(short)0x010E,
			(short)0x010E,
			(short)0x010E,
			(short)0x010E,
			(short)0x010E,
			(short)0x010E,
			(short)0x010E,
			(short)0x010E,
			(short)0x010E,
			(short)0x010E,
			(short)0x010E,
			(short)0x014F,
			(short)0x014F,
			(short)0x014F,
			(short)0x014F,
			(short)0x014F,
			(short)0x014F,
			(short)0x014F,
			(short)0x014F,
			(short)0x014F,
			(short)0x014F,
			(short)0x014F,
			(short)0x014F,
			(short)0x014F,
			(short)0x014F,
			(short)0x014F,
			(short)0x014F,
			(short)0x014F,
			(short)0x0190,
			(short)0x0190,
			(short)0x0190,
			(short)0x0190,
			(short)0x0190,
			(short)0x0190,
			(short)0x0190,
			(short)0x0190,
			(short)0x0190,
			(short)0x0190,
			(short)0x0190,
			(short)0x0190,
			(short)0x0190,
			(short)0x0190,
			(short)0x0190,
			(short)0x0052,
			(short)0x0062,
			(short)0x0062,
			(short)0x0052,
			(short)0x0062,
			(short)0x0052,
			(short)0x0052,
			(short)0x0062,
			(short)0x0062,
			(short)0x00AA,
			(short)0x00AA,
			(short)0x00AA,
			(short)0x0052,
			(short)0x0062,
			(short)0x00AA,
			(short)0x0062,
			(short)0x00AA,
			(short)0x00AA,
			(short)0x0062,
			(short)0x0062,
			(short)0x0052,
			(short)0x0052,
			(short)0x0062,
			(short)0x0062,
			(short)0x00AA,
			(short)0x00AA,
			(short)0x00AA,
			(short)0x0052,
			(short)0x0062,
			(short)0x00AA,
			(short)0x0062,
			(short)0x00AA,
			(short)0x00AA,
			(short)0x0062,
			(short)0x0062,
			(short)0x0052,
			(short)0x0052,
			(short)0x0062,
			(short)0x0062,
			(short)0x00AA,
			(short)0x00AA,
			(short)0x00AA,
			(short)0x0052,
			(short)0x0062,
			(short)0x00AA,
			(short)0x0062,
			(short)0x0062,
			(short)0x00AA,
			(short)0x00AA,
			(short)0x0062,
			// GENERATOR-END: MemorySizes
		};

		for (int i = 0; i < infos.length; i++) {
			int d = data[i];
			FormatterString[] keywords;
			switch (d & MEMORY_KEYWORDS_MASK) {
			// GENERATOR-BEGIN: MemoryKeywordsSwitch
			// ⚠️This was generated by GENERATOR!🦹‍♂️
			case 0x00:
				keywords = new FormatterString[0];
				break;
			case 0x01:
				keywords = byte_ptr_;
				break;
			case 0x02:
				keywords = dword_bcst_;
				break;
			case 0x03:
				keywords = dword_ptr_;
				break;
			case 0x04:
				keywords = fpuenv14_ptr_;
				break;
			case 0x05:
				keywords = fpuenv28_ptr_;
				break;
			case 0x06:
				keywords = fpustate108_ptr_;
				break;
			case 0x07:
				keywords = fpustate94_ptr_;
				break;
			case 0x08:
				keywords = fword_ptr_;
				break;
			case 0x09:
				keywords = oword_ptr_;
				break;
			case 0x0A:
				keywords = qword_bcst_;
				break;
			case 0x0B:
				keywords = qword_ptr_;
				break;
			case 0x0C:
				keywords = tbyte_ptr_;
				break;
			case 0x0D:
				keywords = word_ptr_;
				break;
			case 0x0E:
				keywords = xmmword_ptr_;
				break;
			case 0x0F:
				keywords = ymmword_ptr_;
				break;
			case 0x10:
				keywords = zmmword_ptr_;
				break;
			case 0x11:
				keywords = mem384_ptr_;
				break;
			case 0x12:
				keywords = word_bcst_;
				break;
			// GENERATOR-END: MemoryKeywordsSwitch
			default:
				throw new UnsupportedOperationException();
			}
			infos[i] = new Info(i >= IcedConstants.FIRST_BROADCAST_MEMORY_SIZE, sizes[d >>> SIZE_KIND_SHIFT], keywords);
		}

		allMemorySizes = infos;
	}
}
